package com.rc.evcharger.service.hlhtsk;

import com.rc.evcharger.mapper.hlhtsk.HlhtskBizOperatorMapper;
import com.rc.evcharger.model.hlhtsk.HlhtskBizOperator;
import com.rc.evcharger.model.hlhtsk.HlhtskBizOperatorExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * Create by Yang on 2021/7/12
 */
@Service
public class HlhtskBizOperatorServiceImpl implements HlhtskBizOperatorService {

    @Autowired
    private HlhtskBizOperatorMapper hlhtskBizOperatorMapper;

    @Override
    public HlhtskBizOperatorMapper getMapper() {
        return hlhtskBizOperatorMapper;
    }


    @Override
    public HlhtskBizOperator selectBizOperator(String tenantCode, String hlhtOperatorId) {
        HlhtskBizOperatorExample example = new HlhtskBizOperatorExample();

        example.createCriteria().andTenantCodeEqualTo(tenantCode)
                .andHlhtOperatorIdEqualTo(hlhtOperatorId).andStatusEqualTo("0");


        List<HlhtskBizOperator> list = hlhtskBizOperatorMapper.selectByExample(example);
        if (!CollectionUtils.isEmpty(list)) {
            return list.get(0);
        } else {
            example.createCriteria().andLicenseTenantCodeEqualTo(tenantCode).andHlhtOperatorIdEqualTo(hlhtOperatorId)//按三证合一号码查找
                    .andStatusEqualTo("0");
            list = hlhtskBizOperatorMapper.selectByExample(example);
            if (!CollectionUtils.isEmpty(list)) {
                return list.get(0);
            }
        }
        return null;
    }
}
